package com.example.actearly_revised;

import java.util.ArrayList;

public class Back_Stack {

	public static ArrayList<String> questionList = new ArrayList<String>();
	public static ArrayList<Integer> answerList = new ArrayList<Integer>();
	public static ArrayList<Integer> qidList = new ArrayList<Integer>();
	public static int count = -1;
	public static int temp = 0;
	public static int answerTemp = -1;
	public static int count_back = 0;
	public static boolean backBoolean =false;
	public static boolean newAnswer = false;
	public static boolean storeCount = false;
	public static boolean tempAns = false;

	public static String popQuestion() throws Exception{
		String returnString = "";

		System.out.println("POP           " + count);
		if(count > -1){
			if(tempAns == true){
				count--;
				tempAns = false;
			}
			System.out.println("POP           " + count);
			System.out.println(questionList.get(count));
			returnString =  questionList.get(count);
			answerTemp = count;
			backBoolean = true;
			if(count != 0){
				count--;
			}
			return returnString;
		}
		else{
			storeCount = true;
			return returnString;
		}
	}

	public static int size() throws Exception{
		return questionList.size();
	}

	public static int popAnswer() throws Exception{
		System.out.println("size" + answerList.size());
		System.out.println("anser"+answerTemp);

		int returnInt = answerList.get(answerTemp);
		count_back++;
		return returnInt;
	}

	public static void pushQuestion(String question_input) throws Exception{
		if(!questionList.contains(question_input)){
			if(question_input.equals("")){
				return;
			}
			questionList.add(question_input);
			count++;
			temp++;
			System.out.println("<<<<<<<<<<<<<<<<<<<<");
		}
		System.out.println(question_input);
		System.out.println(questionList);
	}

	public static void pushAnswer(int answer_input, int input_id ) throws Exception{
		if(!qidList.contains(input_id)){
			qidList.add(input_id);
			answerList.add(answer_input);
		}
		System.out.println(answerList);
	}

	public static void newAnswer(int qid) throws Exception{
		if(qidList.contains(qid)){
			count = answerList.size();
		}
		//return true;
	}
	public static void nextbutton() throws Exception{
		//if(count_back == 0){
		if(count >= questionList.size()){
			System.out.println("sdaff"+count_back);
			return;
		}
		count_back--;
		if(count < questionList.size());
		count++;

	}
	public static String getNext() throws Exception{
		if(count >= questionList.size()-1){
			count = questionList.size() -1;
			System.out.println("count" + count);
			System.out.println(questionList.size());
			tempAns = true;
			count_back =0;
			System.out.println("reload");
			return "reload";
		}
		System.out.println("?"+count);
		System.out.println("LL"+ questionList.size());
		return questionList.get(count);
	}

	public static void clear(){
		questionList.clear();
		answerList.clear();
		qidList.clear();
		count = -1;
		temp = 0;
		answerTemp = -1;
		count_back = 0;
		backBoolean =false;
		newAnswer = false;
		storeCount = false;
		tempAns = false;
	}
}
